<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>axios基本使用</title>
</head>

<body>

  <script src="./js/axios.min.js"></script>
  <script>

    // 发送 post 请求
    // 默认传递给后台的是 json 格式的参数
    axios.post('http://localhost:3000/axios', {
      uname: 'Tom',
      pwd: 123456
    }).then((data) => {
      const { data: res } = data
      console.log(res)
    })

    // 发送 put 请求
    axios.put('http://localhost:3000/axios/1', {
      uname: 'Tom',
      pwd: 123456
    }).then((data) => {
      const { data: res } = data
      console.log(res)
    })


    // URLSearchParams 传递字符串形式的数据 --- 做了解
    let params = new URLSearchParams()
    params.append('uname', 'jerry')
    params.append('pwd', 123456897)

    axios.post('http://localhost:3000/axios', params).then((data) => {
      const { data: res } = data
      console.log(res)
    })
  </script>
</body>

</html>